package com.wh.producer8181.controller;

import com.wh.producer8181.bean.User;
import com.wh.producer8181.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @BelongsProject: springcloud
 * @BelongsPackage: com.bruce.controller
 * @Author: bruceliu
 * @QQ:1241488705
 * @CreateTime: 2020-03-16 16:04
 * @Description: TODO
 */
@RestController
@Scope("prototype") //多例的 Spring对象默认单例
public class UserController {

    @Autowired
    UserService userService;

    /**
     * 模拟传递对象
     * @param user
     * @return
     */
    @RequestMapping("/updateUser")
    public int updateUser(@RequestBody User user){
        System.out.println("生产者8181---->要更新的对象是："+user);
        return 1;
    }

    /**
     * 根据ID查询
     * @param id
     * @return
     */
    @RequestMapping("/getById")
    public User getById(@RequestParam Integer id) {
        System.out.println("消费者8181---->查询ID的："+id);
        return userService.queryById(id);
    }

    @RequestMapping("/list")
    public List<User> user_list() {
        System.out.println("我是8181,我被翻牌......");
        return userService.queryUsers();
    }
}
